package com.wzq.solution;

class Solution67 {
    public static String addBinary(String a, String b) {
        
        
        StringBuilder sb = new StringBuilder();
        int al = a.length();
        int bl = b.length();
        
        int s = 0;
        
        while(al >0 || bl >0 || s==1){
            al--;
            char ac = '0';
            if(al>=0){
                ac = a.charAt(al);
            }
            bl--;
            char bc = '0';
            if(bl>=0){
                bc = b.charAt(bl);
            }
            
            if(s == 0){
                if(ac == '0'){
                    if(bc == '0'){
                        sb.append('0');//000
                    }else{
                        sb.append('1');//001
                    }
                }else{//ac == '1'
                    if(bc == '0'){
                        sb.append('1');//010
                    }else{
                        sb.append('0');//011
                        s = 1;
                    }
                }
            }else{//s == 1
                
                if(ac == '0'){
                    if(bc == '0'){
                        sb.append('1');//100
                        s = 0;
                    }else{
                        sb.append('0');//101
                        //s = 1;
                    }
                }else{//ac == '1'
                    if(bc == '0'){
                        sb.append('0');//110
                        //s = 1;
                    }else{
                        sb.append('1');//111
                        //s = 1;
                    }
                }
            }
            
            
        }
        
        return sb.reverse().toString();
        
        
        
    }


    public static void main(String[] args) {
        addBinary("11","1");
    }
}